package com.ddh.codeduck.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.codeduck.pojo.dto.CodeDuckQuestionDTO;
import com.codeduck.pojo.entity.CodeDuckQuestion;
import com.codeduck.pojo.req.CodeDuckQuestionPageReq;
import com.ddh.codeduck.service.ICodeDuckQuestionService;
import com.codeduck.pojo.vo.CodeDuckQuestionVO;
import com.ddhcodeduck.common.result.BaseResponse;
import com.ddhcodeduck.common.result.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 题目表 前端控制器
 * </p>
 *
 * @author ddh
 * @since 2025-07-04
 */
@RestController
@RequestMapping("/code-duck-question")
@Api(tags = "题目信息")
public class CodeDuckQuestionController {

    @Resource
    private ICodeDuckQuestionService codeDuckQuestionService;

    /**
     * 根据题目分类查询题目并且分页
     */
    @PostMapping("/listByQuestionCategory")
    @ApiOperation("根据题目分类查询题目并且分页")
    public BaseResponse<IPage<CodeDuckQuestionVO>> listByQuestionCategory(@RequestBody CodeDuckQuestionPageReq codeDuckQuestionPageReq) {
        IPage<CodeDuckQuestionVO> codeDuckQuestionVOList = codeDuckQuestionService.listByQuestionCategory(codeDuckQuestionPageReq);
        return ResultUtils.success(codeDuckQuestionVOList);
    }

    @PostMapping("/saveOrUpdateQuestion")
    @ApiOperation("新增或者修改题目")
    public BaseResponse<Boolean> saveOrUpdateQuestion(@RequestBody CodeDuckQuestionDTO codeDuckQuestionDTO) {
        return ResultUtils.success(codeDuckQuestionService.mySaveOrUpdateQuestion(codeDuckQuestionDTO));
    }

    @GetMapping("/getQuestionById")
    @ApiOperation(value = "根据ID查询题目")
    public BaseResponse<CodeDuckQuestion> getQuestionById(@RequestParam("id") String id) {
        return ResultUtils.success(codeDuckQuestionService.getById(id));
    }

    @PostMapping("/delete")
    @ApiOperation(value = "批量删除或者单个删除")
    public BaseResponse<Boolean> deleteQuestionByIds(@RequestBody List<String> ids) {
        return ResultUtils.success(codeDuckQuestionService.removeByIds(ids));
    }
}
